package com.hub.nio.socket.bio;


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * @ author 令狐冲
 * @ date & time 2025/1/23 16:29
 */
public class BIOHandler implements Runnable {

    Socket socket;

    BIOHandler(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream inputStream = socket.getInputStream();
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = bufferedInputStream.read(buffer)) != -1) {
                String s = new String(buffer, 0, len);
                System.out.println(s);
            }
            inputStream.close();
            bufferedInputStream.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
